import React, { useEffect, useState } from 'react';
import { Divider, Table, type TableColumnsType } from 'antd';
import type { ColumnType, TableProps } from 'antd/lib/table'; // 引入列类型定义
import type { CompanyList } from '../../../types';
import { getCompanyListApi } from '../../../api';
import { setCompanyList } from '../../../utils/list';
// import { UseSelector,useDispatch, useSelector } from 'react-redux';
// import { RootState,AppDispatch } from '../../../store';
// import { setList,removeList } from '../../../store/modules/company';


const FirstDom: React.FC = () => {
  // 获取企业信息列表
  const [list,setList ] = useState<CompanyList[]>()
  async function companyListApi(){
    const res = await getCompanyListApi()
    setList(res.data)
  }
  useEffect(()=>{
    companyListApi()
  },[])

  const columns: TableColumnsType<CompanyList> = [
    {
      title: '公司名称',
      dataIndex: 'name',
      render: (text: string) => <a>{text}</a>,
    },
    {
      title: '账户',
      dataIndex: 'account',
    },
    {
      title: '银行支行',
      dataIndex: 'bank_name',
    },
  ]
  // 获取Reeac-tedux
  // const list = useSelector((state:RootState)=>state.company.list)
  // const dispatch = useDispatch<AppDispatch>()
  const rowSelection: TableProps<CompanyList>['rowSelection'] = {
    onChange: (selectedRowKeys: React.Key[], selectedRows: CompanyList[]) => {
      console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
      const filteredRows = selectedRows.map(({ is_active, createdAt, updatedAt, ...rest }) => rest);
      setCompanyList(filteredRows);
    },
    // getCheckboxProps: (record: CompanyList) => ({
    //   disabled: record.name === 'Disabled User', // Column configuration not to be checked
    //   name: record.name,
    // }),
  };

  return (
    <>
      <Divider />
      <Table<CompanyList> // ✅ 正确的泛型用法 - 放在变量声明处而非JSX中
        rowSelection={{ type: 'checkbox', ...rowSelection }}
        columns={columns as ColumnType<CompanyList>[]} // 确保列配置符合类型要求
        dataSource={list}
        rowKey="id"
      />
    </>
  );
};

export default FirstDom